package com.book.controller;

import com.book.entity.Reader;
import com.book.service.IReaderService;
import com.book.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
@RequestMapping("/reader")
public class ReaderController {
    @Autowired
    private IReaderService readerService;

    @GetMapping("/getReader")
    public AjaxResult getReader() {
        List<Reader> readers = readerService.getReaders();
        String message;
//        if(readers.size() == 0) {
//            message = "没有记录";
//        }
        message = readers.size() == 0 ? "没有记录" : "查询成功";
        return AjaxResult.success(message).put(AjaxResult.DATA_TAG, readers);
    }

    @GetMapping("/delReader")
    public AjaxResult delReader(@NotBlank(message = "删除id不能为空") @RequestParam String id) {
        readerService.delReader(id);
        return AjaxResult.success("删除成功");
    }

}
